package net;

import message.Login;

public class LoginSender extends Sender{

	public LoginSender(Login login) {
		super(login);
	}

	@Override
	void handleResponse(int response) {
		if(response == Login.ALREADY_LOGGED)
			this.handleAlreadyLogged();
		if(response == Login.WRONG_PASSWORD || response == Login.WRONG_USERNAME)
			this.handleInvalidUserData();
		else
			this.handleLogged();
	}
	
	private void handleAlreadyLogged(){}
	private void handleInvalidUserData(){}
	private void handleLogged(){
		//Creazione USERDATA
		//Attivazione Receiver
		ReceiverThread.startReceiverThread();
	}
	
	public static void sendLogin(String username, String password){
		int inputPort = OlivawPortsClient.getInputPort();
		Login login = new Login(username, password, inputPort, 0, 0);
		
		new Thread(new LoginSender(login)).start();
	}
}
